const mongoose = require('mongoose');
const {Schema, model} = mongoose;

const matchSchema = new Schema({
        matchId:     { type: Number, unique: true },
        competitionId: {type: Number},
        season: {type: Number},
        home_team_id: {type: Number},
        away_team_id: {type: Number},
        /**name:   { type: String },
        area:   { type: String },
        format: { type: String },
        type:   { type: String },
        category: { type: String },
        gender: { type: String },
        divisionLevel: { type: Number },*/
    },{
        toJSON: {
            transform: function(doc, ret, options) {
                delete ret._id;
                delete ret.__v;
                return ret;
            }
        }
    });

matchSchema.static('findById', function(id) { return this.findOne({wyId:id}); });
matchSchema.static('removeById', function(id) { return this.remove({id}); });
matchSchema.static('upsert', function(id, matchData) {
    return this.findOneAndUpdate({id}, matchData, { new:true, upsert: true })
});

module.exports = model('matches', matchSchema);